<template>
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span>条件查询</span>
      </div>
    </template>
    <el-form :model="form" ref="ruleFormRef" inline>
      <el-form-item label="选择年份">
        <lay-date-picker v-model="form.year" type="year" placeholder="请选择开始日期" />
      </el-form-item>
      <el-form-item>
        <el-form-item>
          <lay-select v-model="form.开单科室" filterable placeholder="开单科室">
            <lay-select-option v-for="item in rulesSearch?.开单科室" :key="item" :label="item" :value="item" />
          </lay-select>
        </el-form-item>
        <lay-select v-model="form.执行科室" filterable placeholder="执行科室">
          <lay-select-option v-for="item in rulesSearch?.执行科室" :key="item" :label="item" :value="item" />
        </lay-select>
      </el-form-item>
      <el-form-item>
        <lay-select v-model="form.收费代码" filterable placeholder="收费代码">
          <lay-select-option v-for="item in rulesSearch?.收费代码" :key="item" :label="item" :value="item" />
        </lay-select>
      </el-form-item>
      <el-form-item>
        <lay-select v-model="form.项目名称" filterable placeholder="项目名称">
          <lay-select-option v-for="item in rulesSearch?.项目名称" :key="item" :label="item" :value="item" />
        </lay-select>
      </el-form-item>

      <el-form-item>
        <lay-button type="primary" @click="getDate(ruleFormRef)"> 查询 </lay-button>
        <lay-button type="warnin  g" @click="clear">重置</lay-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup>
import { ref } from 'vue'
import { getSearch_rules } from '@/api/Benefit.js'

const form = ref({
  year: new Date().getTime(),
})
const ruleFormRef = ref(null)
const emits = defineEmits(['submit'])

const getDate = async (ruleFormRef) => {
  if (!ruleFormRef) return
  await ruleFormRef.validate((valid, fields) => {
    if (valid) {
      emits('submit', form.value)
    } else {
      console.log('err')
    }
  })
}

const clear = () => {
  form.value = {}
  form.value = {
    year: new Date().getTime(),
  }
  emits('submit', form.value)
}

const rulesSearch = ref({})
const getRules = async () => {
  const res = await getSearch_rules()
  rulesSearch.value = res.data
  console.log(rulesSearch.value)
}
getRules()
</script>

<style scoped lang="less"></style>